<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>任务报表</title>
    <div th:include="layout/resources :: resources"></div>
</head>
<body>
<div class="container-fluid">
    <div id="toolbar">
        <button class="btn btn-default" onclick="toAdd();">添加</button>
    </div>
    <table id="list"></table>
</div>
</body>
<script type="text/javascript">
    $("#list").framework().bootstrapTable({
        url: "/company/getListByPage",
        columns: [
            {
                field: '',
                title: '序号',
                align: 'center',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            }, {
                field: 'id',
                title: 'AppId',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'companyName',
                title: '公司名称',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'address',
                title: '公司地址',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'contactName',
                title: '联系人姓名',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'telephone',
                title: '联系人电话',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'userName',
                title: '用户名',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'password',
                title: '密码',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'funs',
                title: '业务号',
                align: 'center',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return value + '&nbsp;&nbsp;<a href="javascript:addFun(\'' + row.id + '\');">添加fun</a>';
                }
            }
            , {
                field: 'accessToken',
                title: 'Token',
                align: 'center',
                valign: 'middle'
            }
            , {
                field: 'deadline',
                title: '过期日期',
                align: 'center',
                valign: 'middle'
            }]
    });

    function refresh() {
        $('#list').bootstrapTable('refresh');
    }

    function toAdd() {
        framework.openWindow("/company/toAdd", "80%", "80%", "添加公司");
    }

    function addFun(id) {
        layer.prompt({title: '输入内容，并确认', formType: 2}, function (param, index) {
            $.ajax({
                method: "get",
                url: createUrl('/company/addFun?id=' + id + '&fun=' + param),
                success: function (result) {
                    if (result.success) {
                        refresh();
                        framework.alert("添加成功");
                    } else {
                        framework.alert("添加失败:" + result.error);
                    }
                    layer.close(index);
                }
            })
        });
    }
</script>
</html>
